From 9ebc08e8eaaf9ccbd21f41859bff3f3f7b3d448d Mon Sep 17 00:00:00 2001
From: robertlipe
Date: Sat, 30 Mar 2013 05:14:51 +0000
Subject: [PATCH] Final (?) pass at moving core geocaching structures to
QStrings.
---
gpsbabel/an1.cc | 4 ++--
gpsbabel/cetus.cc | 6 +++---
gpsbabel/csv_util.cc | 8 ++++----
gpsbabel/defs.h | 11 ++++-------
gpsbabel/delbin.cc | 12 ++++++------
gpsbabel/geo.cc | 3 ++-
gpsbabel/geoniche.cc | 2 +-
gpsbabel/html.cc | 8 ++++----
gpsbabel/kml.cc | 2 +-
gpsbabel/maggeo.cc | 6 +++---
gpsbabel/palmdoc.cc | 4 ++--
gpsbabel/src/core/datetime.h | 1 +
gpsbabel/text.cc | 8 ++++----
gpsbabel/unicsv.cc | 4 ++--
gpsbabel/vcf.cc | 2 +-
gpsbabel/waypt.cc | 26 +++++---------------------
16 files changed, 45 insertions(+), 62 deletions(-)
diff --git a/gpsbabel/an1.cc b/gpsbabel/an1.cc
index 458afbba9..480f29a41 100644
--- a/gpsbabel/an1.cc
+++ b/gpsbabel/an1.cc
@@ -769,9 +769,9 @@ Write_One_AN1_Waypoint(const waypoint* wpt)
rec->name = xstrdup(wpt->description);
if (!nogc && wpt->gc_data->id) {
- char* extra = (char*) xmalloc(25 + strlen(wpt->gc_data->placer) + strlen(wpt->shortname));
+ char* extra = (char*) xmalloc(25 + strlen(wpt->gc_data->placer.toUtf8().data()) + strlen(wpt->shortname));
sprintf(extra, "\r\nBy %s\r\n%s (%1.1f/%1.1f)",
- wpt->gc_data->placer,
+ wpt->gc_data->placer.toUtf8().data(),
wpt->shortname, wpt->gc_data->diff/10.0,
wpt->gc_data->terr/10.0);
rec->name = xstrappend(rec->name, extra);
diff --git a/gpsbabel/cetus.cc b/gpsbabel/cetus.cc
index bf646f00c..0e3925ca4 100644
--- a/gpsbabel/cetus.cc
+++ b/gpsbabel/cetus.cc
@@ -505,7 +505,7 @@ cetus_writewpt(const waypoint* wpt)
"" : " (Disabled)",
wpt->gc_data->is_archived==status_true ?
" (Archived)" : "",
- wpt->gc_data->placer,
+ wpt->gc_data->placer.toUtf8().data(),
gs_get_cachetype(wpt->gc_data->type),
gs_get_container(wpt->gc_data->container),
wpt->gc_data->diff/10.0,
@@ -557,8 +557,8 @@ cetus_writewpt(const waypoint* wpt)
}
vdata += strlen(vdata) + 1;
- if (wpt->gc_data->hint) {
- char* hint = xstrdup(wpt->gc_data->hint);
+ if (!wpt->gc_data->hint.isEmpty()) {
+ char* hint = xstrdup(wpt->gc_data->hint.toUtf8().data());
rec->type = WptCache;
strncpy(vdata, hint, NOTESZ + 1) ;
xfree(hint);
diff --git a/gpsbabel/csv_util.cc b/gpsbabel/csv_util.cc
index 90456a4f9..ff6311e81 100644
--- a/gpsbabel/csv_util.cc
+++ b/gpsbabel/csv_util.cc
@@ -2001,12 +2001,12 @@ xcsv_waypt_pr(const waypoint* wpt)
field_is_unknown = wpt->gc_data->type == gt_unknown;
break;
case XT_GEOCACHE_HINT:
- writebuff(buff, fmp->printfc, NONULL(wpt->gc_data->hint));
- field_is_unknown = !wpt->gc_data->hint;
+ writebuff(buff, fmp->printfc, wpt->gc_data->hint.toUtf8().data());
+ field_is_unknown = !wpt->gc_data->hint.isEmpty();
break;
case XT_GEOCACHE_PLACER:
- writebuff(buff, fmp->printfc, NONULL(wpt->gc_data->placer));
- field_is_unknown = !wpt->gc_data->placer;
+ writebuff(buff, fmp->printfc, wpt->gc_data->placer.toUtf8().data());
+ field_is_unknown = !wpt->gc_data->placer.isEmpty();
break;
case XT_GEOCACHE_ISAVAILABLE:
if (wpt->gc_data->is_available == status_false) {
diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h
index 8a709b20d..fb635a98f 100644
--- a/gpsbabel/defs.h
+++ b/gpsbabel/defs.h
@@ -283,11 +283,8 @@ class geocache_data {
has_customcoords(status_unknown),
exported(0),
last_found(0),
- placer(NULL),
placer_id(0),
- hint(NULL),
- favorite_points(0),
- personal_note(NULL)
+ favorite_points(0)
{}
int id; /* The decimal cache number */
geocache_type type:5;
@@ -300,13 +297,13 @@ class geocache_data {
status_type has_customcoords:2;
time_t exported;
time_t last_found;
- char* placer; /* Placer name */
+ QString placer; /* Placer name */
int placer_id; /* Placer id */
- char* hint; /* all these UTF8, XML entities removed, May be not HTML. */
+ QString hint; /* all these UTF8, XML entities removed, May be not HTML. */
utf_string desc_short;
utf_string desc_long;
int favorite_points;
- char* personal_note;
+ QString personal_note;
};
typedef struct xml_tag {
diff --git a/gpsbabel/delbin.cc b/gpsbabel/delbin.cc
index 7846c4467..aabd1a1de 100644
--- a/gpsbabel/delbin.cc
+++ b/gpsbabel/delbin.cc
@@ -1191,8 +1191,8 @@ get_gc_notes(const waypoint* wp, int* symbol, char** notes, unsigned* notes_size
}
if (wp->description) {
gbfputs(wp->description, fd);
- if (wp->gc_data->placer) {
- gbfprintf(fd, " by %s", wp->gc_data->placer);
+ if (!wp->gc_data->placer.isEmpty()) {
+ gbfprintf(fd, " by %s", wp->gc_data->placer.toUtf8().data());
}
gbfputc('\n', fd);
}
@@ -1243,8 +1243,8 @@ get_gc_notes(const waypoint* wp, int* symbol, char** notes, unsigned* notes_size
} else {
gbfprintf(fd, "/T%u\n", wp->gc_data->terr / 10);
}
- if (wp->gc_data->hint && !opt_hint_at_end) {
- gbfprintf(fd, "HINT: %s\n", wp->gc_data->hint);
+ if (!wp->gc_data->hint.isEmpty() && !opt_hint_at_end) {
+ gbfprintf(fd, "HINT: %s\n", wp->gc_data->hint.toUtf8().data());
}
if (!wp->gc_data->desc_short.utfstring.isEmpty() || !wp->gc_data->desc_long.utfstring.isEmpty()) {
gbfputs("DESC: ", fd);
@@ -1298,8 +1298,8 @@ get_gc_notes(const waypoint* wp, int* symbol, char** notes, unsigned* notes_size
gbfputc('\n', fd);
}
}
- if (wp->gc_data->hint && opt_hint_at_end) {
- gbfprintf(fd, "\nHINT: %s\n", wp->gc_data->hint);
+ if (!wp->gc_data->hint.isEmpty() && opt_hint_at_end) {
+ gbfprintf(fd, "\nHINT: %s\n", wp->gc_data->hint.toUtf8().data());
}
gbfputc(0, fd);
*notes_size = fd->memlen;
diff --git a/gpsbabel/geo.cc b/gpsbabel/geo.cc
index 09d1c9235..d72508243 100644
--- a/gpsbabel/geo.cc
+++ b/gpsbabel/geo.cc
@@ -250,7 +250,8 @@ void wpt_name(const char* args, const char** unused)
wpt_tmp->description = xstrappend(wpt_tmp->description,args);
s = xstrrstr(wpt_tmp->description, " by ");
if (s) {
- waypt_alloc_gc_data(wpt_tmp)->placer = xstrdup(s + 4);
+ waypt_alloc_gc_data(wpt_tmp);
+ wpt_tmp->gc_data->placer = xstrdup(s + 4);
if (nuke_placer) {
// Sleaze alert. We're casting away constness and writing into a string
diff --git a/gpsbabel/geoniche.cc b/gpsbabel/geoniche.cc
index 88e347d2d..482e76a14 100644
--- a/gpsbabel/geoniche.cc
+++ b/gpsbabel/geoniche.cc
@@ -685,7 +685,7 @@ geoniche_geostuff(const waypoint* wpt)
return NULL;
}
- snprintf(tbuf, sizeof(tbuf), "\n%s by %s\n\n", gs_get_cachetype(wpt->gc_data->type), wpt->gc_data->placer);
+ snprintf(tbuf, sizeof(tbuf), "\n%s by %s\n\n", gs_get_cachetype(wpt->gc_data->type), wpt->gc_data->placer.toUtf8().data());
gs = xstrappend(gs, tbuf);
/*
diff --git a/gpsbabel/html.cc b/gpsbabel/html.cc
index f24c57f95..c0764471d 100644
--- a/gpsbabel/html.cc
+++ b/gpsbabel/html.cc
@@ -115,8 +115,8 @@ html_disp(const waypoint* wpt)
} else {
gbfprintf(file_out, "%s", wpt->description);
}
- if (wpt->gc_data->placer) {
- gbfprintf(file_out, " by %s", wpt->gc_data->placer);
+ if (!wpt->gc_data->placer.isEmpty()) {
+ gbfprintf(file_out, " by %s", wpt->gc_data->placer.toUtf8().data());
}
}
gbfprintf(file_out, "
\n");
@@ -144,12 +144,12 @@ html_disp(const waypoint* wpt)
gbfprintf(file_out, "%s
\n", tmpstr);
xfree(tmpstr);
}
- if (wpt->gc_data->hint) {
+ if (!wpt->gc_data->hint.isEmpty()) {
char* hint = NULL;
if (html_encrypt) {
hint = rot13(wpt->gc_data->hint);
} else {
- hint = xstrdup(wpt->gc_data->hint);
+ hint = xstrdup(wpt->gc_data->hint.toUtf8().data());
}
gbfprintf(file_out, "Hint: %s
\n", hint);
xfree(hint);
diff --git a/gpsbabel/kml.cc b/gpsbabel/kml.cc
index 6a1f4c1c7..62c9c5be9 100644
--- a/gpsbabel/kml.cc
+++ b/gpsbabel/kml.cc
@@ -1477,7 +1477,7 @@ static void kml_geocache_pr(const waypoint* waypointp)
kml_write_data_element("gc_name", waypointp->url_link_text);
}
- if (waypointp->gc_data->placer) {
+ if (!waypointp->gc_data->placer.isEmpty()) {
kml_write_data_element("gc_placer", waypointp->gc_data->placer);
}
diff --git a/gpsbabel/maggeo.cc b/gpsbabel/maggeo.cc
index 912d42bb4..1eecc0c10 100644
--- a/gpsbabel/maggeo.cc
+++ b/gpsbabel/maggeo.cc
@@ -270,7 +270,7 @@ maggeo_waypt_pr(const waypoint* waypointp)
char* shortname;
char* cname = NULL;
const char* ctype = NULL;
- char* placer = NULL;
+ QString placer;
char* lfounddate = NULL;
char* placeddate = NULL;
@@ -324,8 +324,8 @@ maggeo_waypt_pr(const waypoint* waypointp)
0 : waypointp->altitude);
append(obuf, shortname);
append(obuf, cname);
- append(obuf, placer);
- append(obuf, waypointp->gc_data->hint);
+ append(obuf, placer.toUtf8().data());
+ append(obuf, waypointp->gc_data->hint.toUtf8().data());
append(obuf, ctype);
append(obuf, placeddate);
append(obuf, lfounddate);
diff --git a/gpsbabel/palmdoc.cc b/gpsbabel/palmdoc.cc
index 43c820a6f..404979566 100644
--- a/gpsbabel/palmdoc.cc
+++ b/gpsbabel/palmdoc.cc
@@ -464,12 +464,12 @@ palmdoc_disp(const waypoint *wpt)
docprintf(10+strlen(stripped_html), "\n%s\n", stripped_html);
xfree(stripped_html);
}
- if (wpt->gc_data->hint) {
+ if (!wpt->gc_data->hint.isEmpty()) {
char *hint = NULL;
if (palm_encrypt) {
hint = rot13(wpt->gc_data->hint);
} else {
- hint = xstrdup(wpt->gc_data->hint);
+ hint = xstrdup(wpt->gc_data->hint.toUtf8().data());
}
docprintf(10+strlen(hint), "\nHint: %s\n", hint);
xfree(hint);
diff --git a/gpsbabel/src/core/datetime.h b/gpsbabel/src/core/datetime.h
index 9aad0368d..709da22d4 100644
--- a/gpsbabel/src/core/datetime.h
+++ b/gpsbabel/src/core/datetime.h
@@ -44,6 +44,7 @@ public:
}
DateTime(QDate date, QTime time) : QDateTime(date, time) { }
+ DateTime(QDateTime dt) : QDateTime(dt) { }
// Handle time_tm tm = wpt->creation_time;
diff --git a/gpsbabel/text.cc b/gpsbabel/text.cc
index 7a65a66f1..ef2cd59c1 100644
--- a/gpsbabel/text.cc
+++ b/gpsbabel/text.cc
@@ -143,8 +143,8 @@ text_disp(const waypoint *wpt)
if (strcmp(wpt->description, wpt->shortname)) {
gbfprintf(file_out, "%s", wpt->description);
- if (wpt->gc_data->placer) {
- gbfprintf(file_out, " by %s", wpt->gc_data->placer);
+ if (!wpt->gc_data->placer.isEmpty()) {
+ gbfprintf(file_out, " by %s", wpt->gc_data->placer.toUtf8().data());
}
}
if (wpt->gc_data->terr) {
@@ -162,12 +162,12 @@ text_disp(const waypoint *wpt)
gbfprintf(file_out, "\n%s\n", stripped_html);
xfree(stripped_html);
}
- if (wpt->gc_data->hint) {
+ if (!wpt->gc_data->hint.isEmpty()) {
char *hint = NULL;
if (txt_encrypt) {
hint = rot13(wpt->gc_data->hint);
} else {
- hint = xstrdup(wpt->gc_data->hint);
+ hint = xstrdup(wpt->gc_data->hint.toUtf8().data());
}
gbfprintf(file_out, "\nHint: %s\n", hint);
xfree(hint);
diff --git a/gpsbabel/unicsv.cc b/gpsbabel/unicsv.cc
index d4d3a1ac7..bd7f83ffa 100644
--- a/gpsbabel/unicsv.cc
+++ b/gpsbabel/unicsv.cc
@@ -1479,13 +1479,13 @@ unicsv_waypt_enum_cb(const waypoint *wpt)
if (gc_data->last_found) {
gb_setbit(&unicsv_outp_flags, fld_gc_last_found);
}
- if (gc_data->placer && *gc_data->placer) {
+ if (!gc_data->placer.isEmpty()) {
gb_setbit(&unicsv_outp_flags, fld_gc_placer);
}
if (gc_data->placer_id) {
gb_setbit(&unicsv_outp_flags, fld_gc_placer_id);
}
- if (gc_data->hint && *gc_data->hint) {
+ if (!gc_data->hint.isEmpty()) {
gb_setbit(&unicsv_outp_flags, fld_gc_hint);
}
}
diff --git a/gpsbabel/vcf.cc b/gpsbabel/vcf.cc
index 7c503198d..9c76a6359 100644
--- a/gpsbabel/vcf.cc
+++ b/gpsbabel/vcf.cc
@@ -118,7 +118,7 @@ vcf_disp(const waypoint *wpt)
vcf_print(s);
xfree(s);
} else {
- vcf_print(wpt->gc_data->hint);
+ vcf_print(wpt->gc_data->hint.toUtf8().data());
}
gbfprintf(file_out, "\nEND:VCARD\n");
diff --git a/gpsbabel/waypt.cc b/gpsbabel/waypt.cc
index 2106a97fe..6dbfaa3a7 100644
--- a/gpsbabel/waypt.cc
+++ b/gpsbabel/waypt.cc
@@ -91,21 +91,14 @@ waypt_dupe(const waypoint *wpt)
tmp->gc_data->exported = wpt->gc_data->exported;
tmp->gc_data->last_found = wpt->gc_data->last_found;
tmp->gc_data->placer_id = wpt->gc_data->placer_id;
+ tmp->gc_data->desc_short.utfstring = wpt->gc_data->desc_short.utfstring;
tmp->gc_data->desc_short.is_html = wpt->gc_data->desc_short.is_html;
+ tmp->gc_data->desc_long.utfstring = wpt->gc_data->desc_long.utfstring;
tmp->gc_data->desc_long.is_html = wpt->gc_data->desc_long.is_html;
tmp->gc_data->favorite_points = wpt->gc_data->favorite_points;
- tmp->gc_data->desc_short.utfstring = wpt->gc_data->desc_short.utfstring;
- tmp->gc_data->desc_long.utfstring = wpt->gc_data->desc_long.utfstring;
-
- if (wpt->gc_data->placer) {
- tmp->gc_data->placer = xstrdup(wpt->gc_data->placer);
- }
- if (wpt->gc_data->hint) {
- tmp->gc_data->hint = xstrdup(wpt->gc_data->hint);
- }
- if (wpt->gc_data->personal_note) {
- tmp->gc_data->personal_note = xstrdup(wpt->gc_data->personal_note);
- }
+ tmp->gc_data->placer = wpt->gc_data->placer;
+ tmp->gc_data->hint = wpt->gc_data->hint;
+ tmp->gc_data->personal_note = wpt->gc_data->personal_note;
}
/*
@@ -419,15 +412,6 @@ waypt_free(waypoint *wpt)
if (wpt->gc_data != &empty_gc_data) {
geocache_data *gc_data = (geocache_data *)wpt->gc_data;
- if (gc_data->placer) {
- xfree(gc_data->placer);
- }
- if (gc_data->hint) {
- xfree(gc_data->hint);
- }
- if (gc_data->personal_note) {
- xfree(gc_data->personal_note);
- }
delete gc_data;
}
fs_chain_destroy(wpt->fs);
--
2.30.2